package com.nervenets.web.controller.handler.user.movie;

import com.nervenets.web.controller.handler.Handler;
import com.nervenets.web.entity.MessageCode;
import com.nervenets.web.hibernate.domain.film.Movie;

import javax.servlet.http.HttpServletRequest;

public class MovieDetailHandler extends Handler<MovieDetailParams> {
    @Override
    public String handle(MovieDetailParams params, HttpServletRequest request) throws Exception {
        Movie movie = userDao.findById(params.getMovieId(), Movie.class);
        if (null == movie) return errorMessage(MessageCode.code_404, "影片不存在");
        long salesOfMoney = globalService.getMovieBuyMoney(movie.getId());
        return successMessage(movie, new KeyValue("salesOfMoney", salesOfMoney), new KeyValue("user", globalService.getUser(movie.getUserId())));
    }

    @Override
    public String result() throws Exception {
        return successMessage();
    }
}
